/****************************************************************************
	This file is part of Basqet.

	Basqet is free software: you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation, either version 3 of the License, or
	(at your option) any later version.

	Basqet is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
    along with Basqet.  If not, see <http://www.gnu.org/licenses/>.

****************************************************************************/

#include "tagmanager.h"
#include "tagitem.h"

#include <QAction>

TagManager::TagManager()
		:mTagMenu(new QMenu("Labels"))
{


	QAction	*action  = 0;

//	QMenu* subMenu = new QMenu(tr("ToDo", "tagmenu"), mTagMenu.data());
//	mTagMenu->addMenu(subMenu);

	mIconMap.insert("ToDo-Open", QIcon(":/images/hi16-action-tag_checkbox.png"));
	action = new QAction(mIconMap["ToDo-Open"], tr("ToDo-Open", "tagmenu"), mTagMenu.data());
	action->setData(QVariant("ToDo-Open"));
	mTagMenu->addAction(action);

	mIconMap.insert("ToDo-Closed", QIcon(":/images/hi16-action-tag_checkbox_checked.png"));
	action = new QAction(mIconMap["ToDo-Closed"], tr("ToDo-Closed", "tagmenu"), mTagMenu.data());
	action->setData(QVariant("ToDo-Closed"));
	mTagMenu->addAction(action);

	mIconMap.insert("ToDo-Postponed", QIcon(":/images/hi16-action-tag_for_later.png"));
	action = new QAction(mIconMap["ToDo-Postponed"], tr("ToDo-Postponed", "tagmenu"), mTagMenu.data());
	action->setData(QVariant("ToDo-Postponed"));
	mTagMenu->addAction(action);

	mIconMap.insert("Importance-High", QIcon(":/images/hi16-action-tag_important.png"));
	action = new QAction(mIconMap["Importance-High"], tr("Importance-High", "tagmenu"), mTagMenu.data());
	action->setData(QVariant("Importance-High"));
	mTagMenu->addAction(action);

	mIconMap.insert("Preference-Excellent", QIcon(":/images/hi16-action-tag_preference_excellent.png"));
	action = new QAction(mIconMap["Preference-Excellent"], tr("Preference-Excellent", "tagmenu"), mTagMenu.data());
	action->setData(QVariant("Preference-Excellent"));
	mTagMenu->addAction(action);

	mIconMap.insert("Preference-Good", QIcon(":/images/hi16-action-tag_preference_good.png"));
	action = new QAction(mIconMap["Preference-Good"], tr("Preference-Good", "tagmenu"), mTagMenu.data());
	action->setData(QVariant("Preference-Good"));
	mTagMenu->addAction(action);

	mIconMap.insert("Preference-Bad", QIcon(":/images/hi16-action-tag_preference_bad.png"));
	action = new QAction(mIconMap["Preference-Bad"], tr("Preference-Bad", "tagmenu"), mTagMenu.data());
	action->setData(QVariant("Preference-Bad"));
	mTagMenu->addAction(action);

	mIconMap.insert("Priority-High", QIcon(":/images/hi16-action-tag_priority_high.png"));
	action = new QAction(mIconMap["Priority-High"], tr("Priority-High", "tagmenu"), mTagMenu.data());
	action->setData(QVariant("Priority-High"));
	mTagMenu->addAction(action);

	mIconMap.insert("Priority-Medium", QIcon(":/images/hi16-action-tag_priority_medium.png"));
	action = new QAction(mIconMap["Priority-Medium"], tr("Priority-Medium", "tagmenu"), mTagMenu.data());
	action->setData(QVariant("Priority-Medium"));
	mTagMenu->addAction(action);


	mIconMap.insert("Priority-Low", QIcon(":/images/hi16-action-tag_priority_low.png"));
	action = new QAction(mIconMap["Priority-Low"], tr("Priority-Low", "tagmenu"), mTagMenu.data());
	action->setData(QVariant("Priority-Low"));
	mTagMenu->addAction(action);

	mIconMap.insert("Progress-000", QIcon(":/images/hi16-action-tag_progress_000.png"));
	action = new QAction(mIconMap["Progress-000"], tr("Progress-0%", "tagmenu"), mTagMenu.data());
	action->setData(QVariant("Progress-000"));
	mTagMenu->addAction(action);

	mIconMap.insert("Progress-025", QIcon(":/images/hi16-action-tag_progress_025.png"));
	action = new QAction(mIconMap["Progress-025"], tr("Progress-25%", "tagmenu"), mTagMenu.data());
	action->setData(QVariant("Progress-025"));
	mTagMenu->addAction(action);

	mIconMap.insert("Progress-050", QIcon(":/images/hi16-action-tag_progress_050.png"));
	action = new QAction(mIconMap["Progress-050"], tr("Progress-50%", "tagmenu"), mTagMenu.data());
	action->setData(QVariant("Progress-050"));
	mTagMenu->addAction(action);

	mIconMap.insert("Progress-075", QIcon(":/images/hi16-action-tag_progress_075.png"));
	action = new QAction(mIconMap["Progress-075"], tr("Progress-75%", "tagmenu"), mTagMenu.data());
	action->setData(QVariant("Progress-075"));
	mTagMenu->addAction(action);

	mIconMap.insert("Progress-100", QIcon(":/images/hi16-action-tag_progress_100.png"));
	action = new QAction(mIconMap["Progress-100"], tr("Progress-100%", "tagmenu"), mTagMenu.data());
	action->setData(QVariant("Progress-100"));
	mTagMenu->addAction(action);

	connect(mTagMenu.data(), SIGNAL(triggered(QAction*)), this,SLOT(menuSelection(QAction*)));


}



void TagManager::menuSelection(QAction* action)
{
	if (action)
	{
		emit tagSelected(action->data().toString(), getIcon(action->data().toString()));
	}


}


QIcon TagManager::getIcon(QString tag)
{
	if (mIconMap.contains(tag))
		return mIconMap.value(tag);
	else
		return QIcon();

}

QMenu* TagManager::getTagMenu()
{
	return mTagMenu.data();

}
